<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-recharge"></i> 提现审核
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-row>
                    <el-col :span="10" style="display:flex;justify-content: flex-start;">
                        <el-input
                            v-model="query.name"
                            placeholder="用户手机号"
                            class="handle-input mr10"
                            style="width:120px;"
                        ></el-input>
                        <el-select
                            v-model="query.type"
                            placeholder="选择类型"
                            class="handle-select mr10"
                        >
                            <el-option key="1" label="收入" value="+"></el-option>
                            <el-option key="2" label="支出" value="-"></el-option>
                        </el-select>
                         <el-date-picker
                            v-model="query.time"
                            type="daterange"
                            align="right"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            @change="changeTime"
                            :picker-options="pickerOptions">
                          </el-date-picker>
                        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                        <el-button type="primary" icon="el-icon-download" @click="exportSource">导出数据</el-button>
                    </el-col>
                     <el-col :span="2" style="display:flex;justify-content: flex-start;">
                          <el-button type="warning" >收入：{{totaladd}}</el-button>
                          <el-button type="warning" >支出：{{totalrediuce}}</el-button>
                     </el-col>
                </el-row>
            </div>
            <el-table
                :data="tableData"
                border
                v-loading="loading"
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
                id="buctable"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="id" label="ID" sortable width="55" align="center"></el-table-column>
               
                <el-table-column prop="buc" label="变动BUC" width="155" >
                   <template slot-scope="scope">
                       <span v-if="scope.row.type =='+'" style="color:#67C23A">{{scope.row.type}}</span> <span v-else style="color:red">{{scope.row.type}}</span>{{scope.row.buc}}
                       
                    </template>
                </el-table-column>
                <el-table-column label="剩余buc" prop="raming" align="center" width="155" ></el-table-column>
                <el-table-column prop="remark" label="描述">
                    <template slot-scope="scope">
                      {{scope.row.remark}}[变动用户:{{scope.row.mobile}}]   
                    </template>
                </el-table-column>
                <el-table-column prop="created_at" label="创建时间"></el-table-column>
                
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    :current-page="query.page"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    layout="total, prev, pager, next,sizes"
                    :page-sizes="[0,10, 20, 50,100 ,500,1000]"
                    @size-change="handleSizeChange"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>

export default {
  name: 'deposit',
  data () {
    return {
      query: {
        page: 1,
        pageSize: 10,
        time:[],
        type:'',
        name:'',
      },
      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            const end = new Date();
            const start = new Date(new Date().toLocaleDateString());
            start.setTime(start.getTime());
            picker.$emit('pick', [start, end]);
          }
        },{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      loading: false,
      totaladd:0,
      totalrediuce:0,
      tableData: [],
      multipleSelection: [],
      pageTotal: 0,
      delList: [],
      idx: -1,
      id: -1,
      //获取列表请求
      getList: function () {
        let that = this;
        this.api.post('totalbuc', this.query, res => {
          for (let i in res.data.list.list) {
            res.data.list.list[i].status = res.data.list.list[i].status + '';
          }
          that.tableData = res.data.list.list;
          that.query.page = res.data.list.page;
          that.query.pageSize = res.data.list.pageSize;
          that.pageTotal = res.data.list.pageTotal;
          that.totaladd = res.data.totaladd
          that.totalrediuce = res.data.totalrediuce
        }, undefined, undefined, this);
      },
      //删除请求
      delLists: function (ids, msg) {
        let that = this;
        if (ids.length < 1) {
          this.$message.error('请选择删除的数据');
          return false;
        }
        // 二次确认删除
        this.$confirm('确定要删除吗？', '提示', {
          type: 'warning'
        }).then(() => {
          that.api.delete('delGoodsUnitTime', { ids: ids }, res => {
            that.query.page = 1;
            that.getList();
            that.multipleSelection = [];
            that.$message.success(res.msg);
          }, undefined, undefined, this);
        }).catch(() => { });
      }
    };
  },
  created () {
    this.getList();

  },
  methods: {
    exportSource(){
      this.api.exportExcel(document.querySelector('#buctable'),'BUC数据表')
    },
    handleSizeChange(val){
      console.log(val)
      if(val == 0){
        this.query.pageSize = 100000000;
      }else{
        this.query.pageSize = val;
      }
      this.getList();
    },
    // 触发搜索按钮
    handleSearch () {
      this.$set(this.query, 'page', 1);
      this.getList();
    },
   
    changeTime(e){
      if (!e) {
        return false;
      }
      console.log(e);
      this.query.time = [e[0], e[1]];
    },

    /**
     * 添加编辑
     */
    handleEdit (index, row, status) {
      this.$confirm('确定要' + (status == 1 ? '通过' : '拒绝') + '审核吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.api.put('statusDeposit', { id: row.id, status: status }, res => {
          this.tableData[index].status = status;
          this.$message.success(res.msg);
          this.getList();
        });
      }).catch(() => { });
    },


    // 多选操作
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },

    // 删除操作
    handleDelete (index, row) {
      this.delLists([row.id], '删除成功');
    },
    //批量删除
    delAllSelection () {
      const length = this.multipleSelection.length;
      let str = '';
      this.delList = this.delList.concat(this.multipleSelection);
      let ids = [];
      for (let i = 0; i < length; i++) {
        str += this.multipleSelection[i].name + ' ';
        ids.push(this.multipleSelection[i].id);
      }
      this.delLists(ids, `删除了${str}`);
    },

    // 分页导航
    handlePageChange (val) {
      this.$set(this.query, 'page', val);
      this.getList();
    }
  }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
